package com.example.demo.controller;

import com.example.demo.entity.DTO.MediaUploadDTO;
import com.example.demo.enums.MediaTypeEnum;
import com.example.demo.service.weCon.UploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author jack
 * @data 2021/8/16 3:53 下午
 */
@Api(tags = "素材管理")
@RestController("media")
public class UploadController {

  @Autowired
  private UploadService uploadService;

  @ApiOperation("上传临时素材")
  @PostMapping("file")
  public MediaUploadDTO upload(
      @RequestParam("file")
          MultipartFile file) {
    return uploadService.upload(file, MediaTypeEnum.IMAGE);
  }

  @ApiOperation("获取临时素材")
  @GetMapping("get")
  public void get(HttpServletResponse response,
      @RequestParam
      @NotNull String mediaId) throws Exception {
    uploadService.get(response, mediaId);

  }

  @ApiOperation("上传图片")
  @PostMapping("uploadimg")
  public String uploadimg(
      @RequestParam("file")
          MultipartFile file) {
    return uploadService.uploadimg(file);

  }


}
